package com.wj.chatroom.controller;
import com.wj.chatroom.mapper.FriendMapper;
import com.wj.chatroom.model.Friend;
import com.wj.chatroom.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
@RestController
public class FriendController {
    @Autowired
    private FriendMapper friendMapper;
    @RequestMapping("/friendList")
    public Object getFriendList(HttpServletRequest req){
        HttpSession session = req.getSession(false);
        if(session==null){
            System.out.println("session不存在，用户未登录");
            return new ArrayList<Friend>();
        }
        User user = (User) session.getAttribute("user");
        if(user==null){
            System.out.println("user不存在");
            return new ArrayList<Friend>();
        }
        List<Friend> friendList = friendMapper.selectFriendList(user.getUserId());
        return friendList;
    }
}